| Conditions | 3 |
| Paths | 24 |
| Total Lines | 187 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** global: Clipboard */ |
||
| 66 | $(document).ready(function () { |
||
| 67 | var clipboard = new Clipboard('.copy-link'); |
||
|
|
|||
| 68 | clipboard.on('success', function(e) { |
||
| 69 | var $input = $(e.trigger); |
||
| 70 | $input.tooltip('hide') |
||
| 71 | .attr('data-original-title', t('core', 'Copied!')) |
||
| 72 | .tooltip('fixTitle') |
||
| 73 | .tooltip({placement: 'bottom', trigger: 'manual'}) |
||
| 74 | .tooltip('show'); |
||
| 75 | _.delay(function() { |
||
| 76 | $input.tooltip('hide'); |
||
| 77 | if (OC.Share.Social.Collection.size() === 0) { |
||
| 78 | $input.attr('data-original-title', t('core', 'Copy')) |
||
| 79 | .tooltip('fixTitle'); |
||
| 80 | } else { |
||
| 81 | $input.tooltip('destroy'); |
||
| 82 | } |
||
| 83 | }, 3000); |
||
| 84 | }); |
||
| 85 | clipboard.on('error', function (e) { |
||
| 86 | var $input = $(e.trigger); |
||
| 87 | var actionMsg = ''; |
||
| 88 | if (/iPhone|iPad/i.test(navigator.userAgent)) { |
||
| 89 | actionMsg = t('core', 'Not supported!'); |
||
| 90 | } else if (/Mac/i.test(navigator.userAgent)) { |
||
| 91 | actionMsg = t('core', 'Press ⌘-C to copy.'); |
||
| 92 | } else { |
||
| 93 | actionMsg = t('core', 'Press Ctrl-C to copy.'); |
||
| 94 | } |
||
| 95 | |||
| 96 | $input.tooltip('hide') |
||
| 97 | .attr('data-original-title', actionMsg) |
||
| 98 | .tooltip('fixTitle') |
||
| 99 | .tooltip({placement: 'bottom', trigger: 'manual'}) |
||
| 100 | .tooltip('show'); |
||
| 101 | _.delay(function () { |
||
| 102 | $input.tooltip('hide'); |
||
| 103 | if (OC.Share.Social.Collection.size() == 0) { |
||
| 104 | $input.attr('data-original-title', t('core', 'Copy')) |
||
| 105 | .tooltip('fixTitle'); |
||
| 106 | } else { |
||
| 107 | $input.tooltip("destroy"); |
||
| 108 | } |
||
| 109 | }, 3000); |
||
| 110 | }); |
||
| 111 | // count how many times in each date |
||
| 112 | updateBest(); |
||
| 113 | |||
| 114 | // Temporary hack - Check if we have Nextcloud or ownCloud with an anonymous user |
||
| 115 | var hideAvatars = false; |
||
| 116 | if (!document.getElementById('nextcloud')) { |
||
| 117 | if (OC.currentUser === '') { |
||
| 118 | hideAvatars = true; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | $('.delete-poll').click(function () { |
||
| 123 | deletePoll(this); |
||
| 124 | }); |
||
| 125 | |||
| 126 | $('#switchDetails').click(function () { |
||
| 127 | switchSidebar(); |
||
| 128 | }); |
||
| 129 | |||
| 130 | $('#closeDetails').click(function () { |
||
| 131 | OC.Apps.hideAppSidebar(); |
||
| 132 | }); |
||
| 133 | |||
| 134 | $('.avatar').each(function (i, obj) { |
||
| 135 | updateAvatar(obj); |
||
| 136 | }); |
||
| 137 | |||
| 138 | $('.vote.time').each(function () { |
||
| 139 | var extendedDate = new Date($(this).attr('data-value-utc').replace(/ /g,'T')+'Z'); //Fix display in Safari and IE |
||
| 140 | |||
| 141 | $(this).find('.month').text(extendedDate.toLocaleString(window.navigator.language, {month: 'short'})); |
||
| 142 | $(this).find('.day').text(extendedDate.toLocaleString(window.navigator.language, {day: 'numeric'})); |
||
| 143 | $(this).find('.dayow').text(extendedDate.toLocaleString(window.navigator.language, {weekday: 'short'})); |
||
| 144 | $(this).find('.time').text(extendedDate.toLocaleTimeString(window.navigator.language, {hour: 'numeric', minute:'2-digit', timeZoneName:'short'})); |
||
| 145 | |||
| 146 | }); |
||
| 147 | |||
| 148 | $('#submit_finish_vote').click(function () { |
||
| 149 | var form = document.finish_vote; |
||
| 150 | var ac = document.getElementById('user_name'); |
||
| 151 | if (ac !== null) { |
||
| 152 | if (ac.value.length >= 3) { |
||
| 153 | form.elements.userId.value = ac.value; |
||
| 154 | } else { |
||
| 155 | alert(t('polls', 'You are not registered.\nPlease enter your name to vote\n(at least 3 characters).')); |
||
| 156 | return; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | var check_notif = document.getElementById('check_notif'); |
||
| 160 | var newUserDates = [], newUserTypes = []; |
||
| 161 | $('.poll-cell.active').each(function () { |
||
| 162 | if($(this).hasClass('no')) { |
||
| 163 | newUserTypes.push(0); |
||
| 164 | } else if ($(this).hasClass('yes')) { |
||
| 165 | newUserTypes.push(1); |
||
| 166 | } else if($(this).hasClass('maybe')) { |
||
| 167 | newUserTypes.push(2); |
||
| 168 | } else { |
||
| 169 | newUserTypes.push(-1); |
||
| 170 | } |
||
| 171 | if (isNaN($(this).attr('data-value'))) { |
||
| 172 | newUserDates.push($(this).attr('data-value')); |
||
| 173 | } else { |
||
| 174 | newUserDates.push(parseInt($(this).attr('data-value'))); |
||
| 175 | } |
||
| 176 | }); |
||
| 177 | form.elements.dates.value = JSON.stringify(newUserDates); |
||
| 178 | form.elements.types.value = JSON.stringify(newUserTypes); |
||
| 179 | form.elements.receiveNotifications.value = (check_notif && check_notif.checked) ? 'true' : 'false'; |
||
| 180 | form.elements.changed.value = valuesChanged ? 'true' : 'false'; |
||
| 181 | form.submit(); |
||
| 182 | }); |
||
| 183 | |||
| 184 | $('#submit_send_comment').click(function (e) { |
||
| 185 | e.preventDefault(); |
||
| 186 | var form = document.send_comment; |
||
| 187 | var ac = document.getElementById('user_name_comm'); |
||
| 188 | if (ac !== null) { |
||
| 189 | if(ac.value.length >= 3) { |
||
| 190 | form.elements.userId.value = ac.value; |
||
| 191 | } else { |
||
| 192 | alert(t('polls', 'You are not registered.\nPlease enter your name to vote\n(at least 3 characters).')); |
||
| 193 | return; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | var comment = document.getElementById('commentBox'); |
||
| 197 | if(comment.textContent.trim().length <= 0) { |
||
| 198 | alert(t('polls', 'Please add some text to your comment before submitting it.')); |
||
| 199 | return; |
||
| 200 | } |
||
| 201 | var data = { |
||
| 202 | pollId: form.elements.pollId.value, |
||
| 203 | userId: form.elements.userId.value, |
||
| 204 | commentBox: comment.textContent.trim() |
||
| 205 | }; |
||
| 206 | $('.new-comment .icon-loading-small').show(); |
||
| 207 | $.post(form.action, data, function (data) { |
||
| 208 | var newCommentElement = '<li class="comment flex-column"> ' + |
||
| 209 | '<div class="authorRow user-cell flex-row"> ' + |
||
| 210 | '<div class="avatar missing" title="' + data.userId + '"></div> ' + |
||
| 211 | '<div class="author">' + data.displayName + '</div>' + |
||
| 212 | '<div class="date has-tooltip live-relative-timestamp datespan" data-timestamp="' + Date.now() + '" title="' + data.date + '">' + t('polls', 'just now') + '</div>' + |
||
| 213 | '</div>' + |
||
| 214 | '<div class="message wordwrap comment-content">' + data.comment + '</div>' + |
||
| 215 | '</li>'; |
||
| 216 | |||
| 217 | |||
| 218 | $('#no-comments').after(newCommentElement); |
||
| 219 | |||
| 220 | if (!$('#no-comments').hasClass('hidden')) { |
||
| 221 | $('#no-comments').addClass('hidden'); |
||
| 222 | } |
||
| 223 | |||
| 224 | $('.new-comment .message').text('').focus(); |
||
| 225 | $('.new-comment .icon-loading-small').hide(); |
||
| 226 | |||
| 227 | $('.avatar.missing').each(function (i, obj) { |
||
| 228 | // oC hack |
||
| 229 | if (!hideAvatars) { |
||
| 230 | $(obj).avatar(obj.title, 32); |
||
| 231 | } else { |
||
| 232 | $(obj).imageplaceholder(obj.title); |
||
| 233 | } |
||
| 234 | $(obj).removeClass('missing'); |
||
| 235 | }); |
||
| 236 | |||
| 237 | updateCommentsCount(); |
||
| 238 | }).error(function () { |
||
| 239 | alert(t('polls', 'An error occurred, your comment was not posted.')); |
||
| 240 | $('.new-comment .icon-loading-small').hide(); |
||
| 241 | }); |
||
| 242 | }); |
||
| 243 | |||
| 244 | $('.share input').click(function () { |
||
| 245 | $(this).select(); |
||
| 246 | }); |
||
| 247 | |||
| 248 | $('.has-tooltip').tooltip(); |
||
| 249 | $('.has-tooltip-bottom').tooltip({placement:'bottom'}); |
||
| 250 | updateCounters(); |
||
| 251 | |||
| 252 | }); |
||
| 253 | |||
| 289 |